/*
Date: October 2025
Project: Income and Child Maltreatment: Evidence from a Discontinuity in Tax Benefits
Author: Katherine Rittenhouse
Purpose: This file creates a summary statistics table from the analysis sample
Files in: analysis.dta
Files out: Sumstats_dem.tex (Table 1)
*/

clear all
set more off

use "analysis.dta",clear
local bw 60

ren (ld_med male female momage numref0_2 minage) (MediCal Male Female Mom_Age NumRefs Age1stRef)


gen Mom_LowEd = meduc==1
gen Mom_Black = momrace== 2
gen Mom_White = momrace== 1
gen Mom_AsianPI = momrace== 4
gen Mom_Hispanic = momrace== 5
gen Mom_AmInd = momrace== 3

gen deathage = mdy(deathm,deathd,deathy) - mdy(birth_m,birth_d, birth_y)
gen Death_Age = deathage/365
gen deathagem = deathage/30.4

ren value_hat PredictedValue
ren aftertax_hat PredictedIncome

gen sample = (birth_y<2018 & childorder==1 & abs(et)<60)
replace sample = 0 if birth_y==1999 & birth_m<7
replace sample = 0 if birth_y==2017 & birth_m>7

***cpssample
gen cpssample=(sample==1 & anyref0_2==1)

***deathsample
gen deathsample = (sample==1 & deathage!=. & deathage>=0 & deathage<1095)

*gen fcsample 
gen fcsample = (sample==1 & anypl0_2==1)

gen CPS_0to2 = anyref0_2 
gen Death_0to2 = (deathage!=. & deathage>=0 & deathage<1095)
gen FosterCare_0to2 = anypl0_2 

label var Male "Male Child"
label var MediCal "Birth Paid For by MediCal"
label var Mom_Age "Mother's Age (Years)"
label var Mom_White "White Mother"
label var Mom_Black "Black Mother"
label var Mom_Hispanic "Hispanic Mother"
label var Mom_AsianPI "Asian/Pac. Is. Mother"
label var Mom_AmInd "American Indian Mother"
label var Mom_LowEd "Mother's Educ. $<$ HS"

gen Mom_RaceMiss = momrace==9
gen Mom_EdMiss = meduc==9
gen Mom_AgeMiss = momagebin==9
gen Mom_AnyMissing = max(Mom_AgeMiss,Mom_RaceMiss,Mom_EdMiss)

label var PredictedValue "Predicted Tax Value of Dec. Birth (\\$)"
label var PredictedIncome "Predicted Household Income (\\$)"
label var CPS_0to2 "Referred to CPS Before Age 3"
label var FosterCare_0to2 "Placed in Foster Care Before Age 3"
label var Death_0to2 "Died Before Age 3"
label var Age1stRef "Age at First CPS Referral (Years)"
label var NumRefs "\# Referrals Before Age 3"
label var Death_Age "Age at Death (Years)"
label var mom_fb "Foreign-Born Mother"
label var Mom_AnyMissing "Mother Missing Data"

label var numalneglect0_2  "\# Allegation Neglect"
label var numalphysical0_2 "\# Allegation Physical Abuse"
label var numalemotional0_2 "\# Allegation Emotional Abuse"
label var numalother0_2 "\# Allegation Other"
label var numrepnonmand0_2 "\# Reported by Non-Mandated"
label var numrepschool0_2 "\# Reported by Education Professional"
label var numreplegprof0_2 "\# Reported by Legal Professional"
label var numrepmedprof0_2 "\# Reported by Medical Professional"
label var numrepcws0_2 "\# Reported by CWS"
label var numrepother0_2 "\# Reported by Other"

label var lowinc "Low Income ($<$200\% FPL)"
replace NumRefs=0 if NumRefs==.

eststo clear
estpost sum Male Mom_White Mom_Black Mom_Hispanic Mom_AsianPI Mom_AmInd mom_fb Mom_AnyMissing MediCal Mom_Age Mom_LowEd  PredictedValue PredictedIncome lowinc CPS_0to2 FosterCare_0to2 Age1stRef NumRefs numalneglect0_2 numalphysical0_2 numalemotional0_2 numalother0_2 numrepnonmand0_2 numrepschool0_2 numreplegprof0_2 numrepmedprof0_2 numrepcws0_2 numrepother0_2 Death_0to2 Death_Age if sample==1
est store all

estpost sum Male Mom_White Mom_Black Mom_Hispanic Mom_AsianPI Mom_AmInd mom_fb Mom_AnyMissing MediCal Mom_Age Mom_LowEd  PredictedValue PredictedIncome lowinc CPS_0to2 FosterCare_0to2 Age1stRef NumRefs numalneglect0_2 numalphysical0_2 numalemotional0_2 numalother0_2 numrepnonmand0_2 numrepschool0_2 numreplegprof0_2 numrepmedprof0_2 numrepcws0_2 numrepother0_2 Death_0to2 Death_Age if cpssample==1
est store cps 

estpost sum Male Mom_White Mom_Black Mom_Hispanic Mom_AsianPI Mom_AmInd mom_fb Mom_AnyMissing MediCal Mom_Age Mom_LowEd  PredictedValue PredictedIncome lowinc CPS_0to2 FosterCare_0to2 Age1stRef NumRefs numalneglect0_2 numalphysical0_2 numalemotional0_2 numalother0_2 numrepnonmand0_2 numrepschool0_2 numreplegprof0_2 numrepmedprof0_2 numrepcws0_2 numrepother0_2 Death_0to2 Death_Age if fcsample==1
est store fc 

estpost sum Male Mom_White Mom_Black Mom_Hispanic Mom_AsianPI Mom_AmInd mom_fb Mom_AnyMissing MediCal Mom_Age Mom_LowEd  PredictedValue PredictedIncome lowinc CPS_0to2 FosterCare_0to2 Age1stRef NumRefs numalneglect0_2 numalphysical0_2 numalemotional0_2 numalother0_2 numrepnonmand0_2 numrepschool0_2 numreplegprof0_2 numrepmedprof0_2 numrepcws0_2 numrepother0_2 Death_0to2 Death_Age if deathsample==1
est store death 

esttab all cps fc death using "Sumstats_dem.tex", label replace mtitles("\textbf{\emph{All}}" "\textbf{\emph{CPS}}" "\textbf{\emph{Foster Care}}" "\textbf{\emph{Death}}" ) cells("mean(fmt(3))") nonumber f alignment(S) booktabs


